package cn.itsource.service.impl;

import cn.itsource.domain.ArticleType;
import cn.itsource.mapper.ArticleTypeMapper;
import cn.itsource.query.Query;
import cn.itsource.service.ArticleTypeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class ArticleTypeServiceImpl implements ArticleTypeService {


    @Autowired
    private ArticleTypeMapper articleTypeMapper;


    @Override
    public List<ArticleType> findAll() {
        return articleTypeMapper.findAll();
    }

    @Override
    public ArticleType findOne(Long id) {
        return articleTypeMapper.findOne(id);
    }

    @Override
    public void add(ArticleType articleType) {
        articleTypeMapper.add(articleType);
    }

    @Override
    public void update(ArticleType articleType) {
        articleTypeMapper.update(articleType);
    }

    @Override
    public void delete(Long id) {
        articleTypeMapper.delete(id);
    }

    //分页+模糊查询
    @Override
    public PageInfo<ArticleType> pageQuery(Query query) {
        PageHelper.startPage(query.getCurrentPage(),query.getPageSize());
        List<ArticleType> articleTypeList = articleTypeMapper.pageQuery(query);
        return new PageInfo<>(articleTypeList);
    }

    //批量删除
    @Override
    public void patchdel(Long[] ids) {
        articleTypeMapper.patchdel(ids);
    }
}
